<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html class="no-js" lang="">
<head>
    <jsp:include page="../layout/head.jsp">
        <jsp:param name="title" value="收藏夹"/>
        <jsp:param name="cssName" value="user-favorite"/>
    </jsp:include>
</head>
<body>
<jsp:include page="../layout/nav.jsp"/>

<div class="container">


    <jsp:include page="userleft.jsp"/>

    <div class="main">

        <div class="page-wrapper">
            <h1 class="title">文章收藏</h1>

            <ul class="fav-list">
                <c:if test="${empty page.list}">暂无文章</c:if>
                <c:forEach items="${page.list}" var="topic">
                <li class="split-line">
                    <div class="fav-info">
                        <p class="fav-author"><a href="#">${topic.user.name}</a>
                            <time>${topic.createTime}</time>
                        </p>
                        <h3 class="fav-title">
                            <a href="${pageContext.request.contextPath}/topic/get?id=${topic.id}">${topic.title}</a>
                        </h3>
                        <p class="fav-count">${topic.hits}阅读~ ${topic.messages}评论 ~ ${topic.favourites}喜欢</p><button onclick="collection(${topic.id})">取消收藏</button>
                    </div>
                    <a href="#" class="fav-img">
                        <img src="${pageContext.request.contextPath}${topic.photo.img}" alt="">
                    </a>
                </li>
                </c:forEach>
            </ul>
        </div>

    </div>

</div>
<jsp:include page="../layout/footer.jsp"/>
<script>
    function collection(id) {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/delFavourite",
            type: "get",
            data: {"id": id},
            success: function (data) {
                if (data == "true") {
                    window.location.reload();
                }
            }
        })
    }
</script>
</body>
</html>
